package qinius

import (
	"time"

	"github.com/qiniu/api.v7/auth/qbox"
	"github.com/qiniu/api.v7/storage"
)

//GetPublicToken 七牛云，获取公有上传Token
func GetPublicToken() string {
	putPolicy := storage.PutPolicy{Scope: "qjpublic"}
	mac := qbox.NewMac(defKey, defSecret)
	return putPolicy.UploadToken(mac)
}

//GetPrivateToken 七牛云，获取私有上传Token
func GetPrivateToken() string {
	putPolicy := storage.PutPolicy{
		Scope: "qjbucket",
	}
	mac := qbox.NewMac(defKey, defSecret)
	return putPolicy.UploadToken(mac)
}

//GetPrivateURL 七牛云，获取私有下载URL,有效期1小时
func GetPrivateURL(key string) string {
	mac := qbox.NewMac(defKey, defSecret)
	domain := "https://qny.qjnice.com"
	deadline := time.Now().Add(time.Second * 3600).Unix() //1小时有效期
	return storage.MakePrivateURL(mac, domain, key, deadline)
}
